<?php
	//var_dump($_POST);
	session_start();
	//var_dump($_SESSION['vcode']);
	//验证输入的验证码和 随机的验证码 是否一样
	if(empty($_POST['yanzheng'] || $_POST['yanzheng'] != $_SESSION['vcode'])){
		header('location:./reg2.php');
		exit;
	}
	
	
	$userName = $_POST['userName'];
	$password = md5($_POST['password']);
	$auth = $_POST['level'];
	
	//判断账号密码 是否为空
	if(empty($_POST['userName']) || empty($_POST['password']) || empty($_POST['rePassword'])){
		header('location:./addUser.php');
		exit;
	}
	//判断密码是否一样
	if($_POST['password'] != $_POST['rePassword']){
		header('location:./addUser.php');
		exit;
	}
	
	
	//1 连接数据库
	$con = mysqli_connect('localhost','root','www');
	//2 连接字符集
	mysqli_set_charset($con,'utf8');
	//3 选择数据库
	mysqli_select_db($con,'admin');
	//4 准备SQL语句
	$SQL = "insert into user (userName,password,auth) values ('{$userName}','{$password}',{$auth})";
	//5 执行SQL语句
	mysqli_query($con,$SQL);
	//6 处理结果
	if(mysqli_affected_rows($con) >= 1){
		$SQL2 = "insert into userDetail (name) values ('{$userName}')";
		mysqli_query($con,$SQL2);
	
		header('location:./userList.php');
	}else{
		header('location:./addUser.php');
	}
	
	//7 关闭数据库
	mysqli_close($con);
	
?>